<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script>
        // const user = {
        //     name:'xm',
        //     age:18
        // }
        // const proxy = new Proxy(user,{
        //     // receiver 当前 proxy
        //     get(target,key,receiver){
        //         console.log('get')
        //         return Reflect.get(target,key,receiver)
        //     },
        //     set(target,key,value,receiver){
        //         console.log('set',receiver)
        //        return Reflect.set(target,key,value,receiver)
        //     },
        //     deleteProperty(target,key){
        //         console.log('delete')
        //         return Reflect.deleteProperty(target,key)
        //     }
        // })
        // proxy.name = 'xh'
        // delete proxy.age
        // console.log(proxy,user,proxy.name)

        const obj = {
            get name(){
                console.log(1,this)
                return this.age
            }
        }
        const proxy = new Proxy(obj,{
            get(target,key,receiver){
                console.log(2,key)
                if(key === 'age'){
                    return 18
                }
                // return Reflect.get(target,key) // this 指向 obj
                return Reflect.get(target,key,receiver) // this 指向 proxy，两次访问 get
            }
        })
        console.log(proxy.name)
    </script>
</body>
</html>
